﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using com.pro2e.console.service.auth.dao;
using com.pro2e.console.service.auth.vo;
using System.Collections.Generic;

/// <summary>
/// TreeveiwService 的摘要描述
/// </summary>
/// 

namespace com.pro2e.web.treeview
{
    public class TreeveiwService
    {
        public TreeveiwService()
        {
            
        }

        public TreeView Populate( string userId) 
        {
            TreeView treeView = new TreeView();

            MenuFuncDao menuFuncDao = new MenuFuncDao();

            IList<MenuFunc> menuFuncList = menuFuncDao.GetTopMenuFuncList();

            var result = from data in menuFuncList
                         where data.ParentMenu == null
                         select data;

            foreach (MenuFunc menu in result)
            {
                TreeNode treeNode = new TreeNode(menu.MenuFuncName, "");

                if (menu.SubFuncs.Count > 0)
                {
                    foreach (MenuFunc subMenu in menu.SubFuncs)
                    {
                        //TreeNode subTreeNode = new TreeNode(subMenu.MenuFuncName, subMenu.Id.ToString());
                        TreeNode subTreeNode = new TreeNode(subMenu.MenuFuncName, subMenu.MainPath);
                        //subTreeNode.NavigateUrl = "~/" + subMenu.MainPath;
                        treeNode.ChildNodes.Add(subTreeNode);
                    }
                }

                treeView.Nodes.Add(treeNode);
            }
            return treeView;
        }
    }
}